const cloud = require('wx-server-sdk');

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
});

// 获取小程序二维码云函数入口函数
exports.main = async (event, context) => {
  // 获取小程序二维码的buffer
  let uName = event.worker
  let uId = event.uuid
  let zpath = `/pages/index/index?option=default&area=江门&worker=${uName}&uuid=${uId}`
  console.log('二维码冷酷', zpath)
  const resp = await cloud.openapi.wxacode.get({
    path: zpath
  });
  const { buffer } = resp;
  // 将图片上传云存储空间
  console.log('cloud test func')
  const upload = await cloud.uploadFile({
    cloudPath: 'wwcode.png',
    fileContent: buffer
  });
  return upload.fileID;
};
